package org.jst4me.hadoop.util;

import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.jst4me.common.StringUtil;
import org.jst4me.common.exceptions.ArgumentException;
import org.jst4me.hadoop.util.exceptions.DirectoryExistException;
import org.jst4me.hadoop.util.exceptions.NotInitException;

import java.io.IOException;
import java.io.InputStream;

public interface HDFSAccessInterface {

    /**
     * init hadoop server and port
     * @param serverPath hadoop server path and port . format: hdfs://servername:port
     * @throws ArgumentException
     * @throws IOException
     */
    void init(String serverPath) throws ArgumentException, IOException;

    /**
     *  get an instance for org.apache.hadoop.fs.FileSystem
     * @return
     * @throws NotInitException
     */
    FileSystem getFileSystem() throws NotInitException;

    /**
     * make an directory on hadoop file system
     * @param filePathOnHDFS  directory path  example: /user/hadoop/test
     * @throws IOException
     * @throws NotInitException
     * @throws ArgumentException
     * @throws DirectoryExistException
     */
    void makeDir(String filePathOnHDFS) throws IOException, NotInitException, ArgumentException,DirectoryExistException;

    /**
     * copy local file to hadoop file system
     * @param localFilePath local file absoulte path
     * @param hdfsFilePath hdfs file path
     * @param delSrc  delete local file
     * @param override override hdfs file
     * @throws IOException
     * @throws NotInitException
     * @throws ArgumentException
     */
    void copyFileToHDFS(String localFilePath, String hdfsFilePath, boolean delSrc, boolean override) throws IOException, NotInitException, ArgumentException;

    /**
     * download hdfs file to InputStream
     * @param hdfsFilePath hdfs file path
     * @return
     */
    InputStream downToInputStream(String hdfsFilePath) throws NotInitException, ArgumentException, IOException;

    /**
     * close hdfs instance
     * @throws NotInitException
     * @throws IOException
     */
    void close() throws NotInitException, IOException;

    /**
     * append local file to hdfs file
     * @param localFilePath
     * @param hdfsFilePath
     * @throws NotInitException
     * @throws ArgumentException
     * @throws IOException
     */
    void append(String localFilePath, String hdfsFilePath) throws NotInitException, ArgumentException,IOException;
}
